function h = unitTestConstructHist()

	imglist1 = {'0.aaa.0.30.0.bmp', ...
				'0.aab.0.30.0.bmp', ...
				'0.aaj.0.30.0.bmp', ...
				'0.aam.0.30.0.bmp', ...
				'0.aan.0.30.0.bmp', ...
				'0.aao.0.30.0.bmp', ...
				'0.aar.0.30.0.bmp', ...
				'0.aas.0.30.0.bmp', ...
				'0.aba.0.30.0.bmp', ...
				'0.abj.0.30.0.bmp', ...
				'0.abk.0.30.0.bmp', ...
				'1.acc.0.30.0.bmp', ...
				'1.acd.0.30.0.bmp', ...
				'1.ace.0.30.0.bmp', ...
				'1.adb.0.30.0.bmp', ...
				'1.adc.0.30.0.bmp', ...
				'1.add.0.30.0.bmp', ...
				'1.ade.0.30.0.bmp', ...
				'2.adg.0.30.0.bmp', ...
				'2.adh.0.30.0.bmp'
				}

	imglist2 = {'0.aaa.0.30.0.bmp', ...
				'0.aaa.0.30.90.bmp', ...
				'0.aaa.0.30.180.bmp', ...
				'0.aaa.0.30.270.bmp', ...
				'0.aaa.0.45.0.bmp', ...
				'0.aaa.0.45.30.bmp', ...
				'0.aaa.0.45.60.bmp', ...
				'0.aaa.0.45.90.bmp', ...
				'0.aaa.0.45.120.bmp', ...
				'0.aaa.0.45.150.bmp', ...
				'0.aaa.0.60.0.bmp', ...
				'0.aaa.0.60.30.bmp', ...
				'0.aaa.0.60.60.bmp', ...
				'0.aaa.0.60.90.bmp', ...
				'0.aaa.0.60.120.bmp', ...
				'0.aaa.0.75.0.bmp', ...
				'0.aaa.0.75.30.bmp', ...
				'0.aaa.0.75.60.bmp', ...
				'0.aaa.0.75.90.bmp', ...
				'0.aaa.0.75.120.bmp'
				}

	imglist3 = {'1.acd.0.30.0.bmp', ...
				'1.acd.0.30.90.bmp', ...
				'1.acd.0.30.180.bmp', ...
				'1.acd.0.30.270.bmp', ...
				'1.acd.0.45.0.bmp', ...
				'1.acd.0.45.30.bmp', ...
				'1.acd.0.45.60.bmp', ...
				'1.acd.0.45.90.bmp', ...
				'1.acd.0.45.120.bmp', ...
				'1.acd.0.45.150.bmp', ...
				'1.acd.0.60.0.bmp', ...
				'1.acd.0.60.30.bmp', ...
				'1.acd.0.60.60.bmp', ...
				'1.acd.0.60.90.bmp', ...
				'1.acd.0.60.120.bmp', ...
				'1.acd.0.75.0.bmp', ...
				'1.acd.0.75.30.bmp', ...
				'1.acd.0.75.60.bmp', ...
				'1.acd.0.75.90.bmp', ...
				'1.acd.0.75.120.bmp'
				}
			
	h = [];
	figure;
	for i=1:length(imglist1)
		tmp = unitConstructHistogram('../responses/', imglist1{i}, 10);
		subplot(4,5,i); hist(tmp,200); drawnow;
	end

	figure;
	for i=1:length(imglist2)
		tmp = unitConstructHistogram('../responses/', imglist2{i}, 10);
		subplot(4,5,i); hist(tmp,200); drawnow;
	end

	figure;
	for i=1:length(imglist3)
		tmp = unitConstructHistogram('../responses/', imglist3{i}, 10);
		subplot(4,5,i); hist(tmp,200); drawnow;
	end
	
end


function labeledPix = unitConstructHistogram(directory, data, clusterNr)
	load Dictionary3.mat

	img_nr = 8;
	nTextons	= size(dictionary,1);

	responses = loadResponses(directory, data, img_nr);
	textonHistogram = zeros(nTextons,1);

	npix = size(responses,1);

	for u = 1:npix
		tmp = sum((dictionary-ones(nTextons,1)*responses(u,:)).^2,2);
		[mindist,index] = min(tmp);
% 		textonHistogram(index) = textonHistogram(index)+1.0;%/npix;
		labeledPix(u) = index;
	end
end